package com.mapper;

import com.POJO.Subject;
import java.util.List;

import org.apache.ibatis.annotations.*;


/**
 * @Package com.mapper
 * @Date 2024-05-23 11:27
 * 科目相关数据库操作
 */

@Mapper
public interface SubjectMapper {
    // 获取所有科目
    @Select("SELECT * FROM subjects")
    List<Subject> getAllSubjects();

    // 根据教师ID获取其教授的所有科目
    @Select("select * from subjects where teacher_id =#{teacherId}")
    List<Subject> getSubjectsByTeacherId(int teacherId);

    // 新增科目
    @Insert("insert into subjects(subject_id,subject_name,teacher_id) values (#{subjectId},#{subjectName},#{teacherId})")
    @Options(useGeneratedKeys = true, keyProperty = "subjectId")
    void insertSubject(Subject subject);

    // 更新科目信息
    @Update("update subjects set subject_name = #{subjectName}")
    void updateSubject(Subject subject);

    // 删除科目
    @Delete("DELETE FROM subjects WHERE subject_id = #{subjectId}")
    void deleteSubject(int subjectId);
}
